package cn.ztuo.bitrade.service;

import cn.ztuo.bitrade.dao.AccessServiceChargeDao;
import cn.ztuo.bitrade.entity.AccessServiceCharge;
import cn.ztuo.bitrade.entity.Coin;
import cn.ztuo.bitrade.service.Base.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

/**
 * @author: Xiazt
 * @date: 2020-05-11 11:08
 */
@Service
public class AccessServiceChargeService extends BaseService {

    @Autowired
    private AccessServiceChargeDao accessServiceChargeDao;

    public Page<AccessServiceCharge> getByPage(AccessServiceCharge accessServiceCharge) {
        // 排序条件
        Sort sort = new Sort(Sort.Direction.ASC, "createTime");
        Pageable pageable = new PageRequest(accessServiceCharge.getPageNum() - 1, accessServiceCharge.getPageSize(), sort);

        return accessServiceChargeDao.findAll(pageable);
    }

    public AccessServiceCharge saveOrUpdate(AccessServiceCharge accessServiceCharge) {
        return accessServiceChargeDao.save(accessServiceCharge);
    }

    public void delete(Long id) {
        accessServiceChargeDao.delete(id);
    }

    public AccessServiceCharge findByCoin(Coin coin) {
        return accessServiceChargeDao.findByCoin(coin);
    }

}
